from itertools import combinations

#有N个球
ball_number = 3
red_balls = []
green_balls = []
basket = []
basket_2 = []
basket_3 = []
temp_list = []
result = []
temp = ""

for item in range(ball_number):
    red_balls.append('r' + str(item))
    green_balls.append('g' + str(item))

for red_ball in red_balls:
    for green_ball in green_balls:
        if red_ball[:1] != green_ball[:1]:
            basket.append(red_ball+green_ball)

for item in basket:
    if item[1] == item[3]:
        basket.remove(item)

#一个篮子里可以放的所有组合。
for item in combinations(basket, 2):
    if item[0][0:2] != item[1][0:2] and item[0][2:4]!=item[1][2:4]:
        basket_2.append(item)



for item in combinations(basket, ball_number):
    red_number_list = []
    green_number_list = []
    for i in range(ball_number):
        red_number = item[i][1]
        green_number = item[i][3]
        red_number_list.append(red_number)
        green_number_list.append(green_number)
    set_red = set(red_number_list)
    set_green = set(green_number_list)
    if (len(set_red)==len(red_number_list)) and (len(set_green)==len(green_number_list)):
        result.append(item)


print(len(result))

print("{}个球共有{}种方法".format(ball_number,len(result)))
print("方法分别是")
for item in result:
    print(item)